Skip to main content

object

>>> dir(object)
['__class__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

Dunder methods

Dunder MethodOperationExample (normal syntax)Example (dunder call)
__init__Initializeobject()object().__init__()
__str__String representationstr(object())object().__str__()
__repr__Developer representationrepr(object())object().__repr__()
__eq__Equalityobject() == object()object().__eq__(object())
__hash__Hash valuehash(object())object().__hash__()
__getattribute__Attribute lookupobj.attrobj.__getattribute__('attr')
__setattr__Attribute setobj.attr = 1obj.__setattr__('attr',1)
__delattr__Attribute deletedel obj.attrobj.__delattr__('attr')
Dunder MethodOperationExample (normal syntax)Example (dunder call)
__get__Access attributeobj.xprop.__get__(obj, type(obj))
__set__Assign valueobj.x = 5prop.__set__(obj, 5)
__delete__Delete valuedel obj.xprop.__delete__(obj)